package com.rongji.cms.tools.temp.db.entity;


import com.rongji.cms.tools.temp.db.annotation.CompareIgnore;
import com.rongji.cms.tools.temp.db.annotation.CompareInfo;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

/**
 * @author yang
 * @create 2023/1/13
 * fixme  oracle的ColumnProp跟mysql的还不太一样，需要查下都有哪些字段及含义
 **/
public class OracleColumnProp {


    /**
     * table_name
     */
    @CompareIgnore
    @CompareInfo(mean = "表名")
    private String tableName;

    /**
     * column_name
     */
    @CompareInfo(mean = "列名")
    private String columnName;

    /**
     * data_type
     */
    @CompareInfo(mean = "类型")
    private String dataType;

    /**
     * data_type_mod
     */
    @CompareIgnore
    @CompareInfo(mean = "类型mod?")
    private String dataTypeMod;


    /**
     * data_length
     */
    @CompareInfo(mean = "类型长度")
    private static String dataLength;

    /**
     * data_precision
     */
    @CompareIgnore
    @CompareInfo(mean = "数据整数精度")
    private String dataPrecision;

    /**
     * data_scale
     */
    @CompareIgnore
    @CompareInfo(mean = "数据小数精度")
    private String dataScale;

    /**
     * nullable
     */
    @CompareInfo(mean = "是否为空")
    private String nullable;

    /**
     * column_id
     */
    @CompareIgnore
    @CompareInfo(mean = "列id")
    private String columnId;

    /**
     * default_length
     */
//    @CompareIgnore
    @CompareInfo(mean = "默认长度")
    private String defaultLength;

    /**
     * data_default
     */
    @CompareIgnore
    @CompareInfo(mean = "默认值？")
    private String dataDefault;

    /**
     * num_distinct
     */
    @CompareIgnore
    @CompareInfo(mean = "字段区分度？")
    private String numDistinct;

    /**
     * low_value
     */
    @CompareIgnore
    @CompareInfo(mean = "最小值？")
    private String lowValue;

    /**
     * high_value
     */
    @CompareIgnore
    @CompareInfo(mean = "最大值？")
    private String highValue;

    /**
     * num_nulls
     */
    @CompareIgnore
    @CompareInfo(mean = "列的null值数量？")
    private String numNulls;

    /**
     * density
     */
    @CompareIgnore
    @CompareInfo(mean = "密度？")
    private String density;

    /**
     * num_buckets
     */
    @CompareIgnore
    @CompareInfo(mean = "桶数？")
    private String numBuckets;

    /**
     * sample_size
     */
    @CompareIgnore
    @CompareInfo(mean = "样品大小？")
    private String sampleSize;

    /**
     * character_set_name
     */
    @CompareIgnore
    @CompareInfo(mean = "字符集名称")
    private String characterSetName;

    /**
     * char_col_decl_length
     */
    @CompareIgnore
    @CompareInfo(mean = "列字符长度？")
    private String charColDeclLength;

    /**
     * global_stats
     */
    @CompareIgnore
    @CompareInfo(mean = "全局状态？")
    private String globalStats;

    /**
     * user_stats
     */
    @CompareIgnore
    @CompareInfo(mean = "用户状态？")
    private String userStats;

    /**
     * avg_col_len
     */
    @CompareIgnore
    @CompareInfo(mean = "平均列长度?")
    private String avgColLen;

    /**
     * char_length
     */
    @CompareIgnore
    @CompareInfo(mean = "字符长度")
    private String charLength;

    /**
     * char_used
     */
    @CompareIgnore
    @CompareInfo(mean = "字符是否使用？")
    private String charUsed;


    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

    public String getColumnName() {
        return columnName;
    }

    public void setColumnName(String columnName) {
        this.columnName = columnName;
    }

    public String getDataType() {
        return dataType;
    }

    public void setDataType(String dataType) {
        this.dataType = dataType;
    }

    public String getDataTypeMod() {
        return dataTypeMod;
    }

    public void setDataTypeMod(String dataTypeMod) {
        this.dataTypeMod = dataTypeMod;
    }

    public String getDataLength() {
        return dataLength;
    }

    public void setDataLength(String dataLength) {
        this.dataLength = dataLength;
    }

    public String getDataPrecision() {
        return dataPrecision;
    }

    public void setDataPrecision(String dataPrecision) {
        this.dataPrecision = dataPrecision;
    }

    public String getDataScale() {
        return dataScale;
    }

    public void setDataScale(String dataScale) {
        this.dataScale = dataScale;
    }

    public String getNullable() {
        return nullable;
    }

    public void setNullable(String nullable) {
        this.nullable = nullable;
    }

    public String getColumnId() {
        return columnId;
    }

    public void setColumnId(String columnId) {
        this.columnId = columnId;
    }

    public String getDefaultLength() {
        return defaultLength;
    }

    public void setDefaultLength(String defaultLength) {
        this.defaultLength = defaultLength;
    }

    public String getDataDefault() {
        return dataDefault;
    }

    public void setDataDefault(String dataDefault) {
        this.dataDefault = dataDefault;
    }

    public String getNumDistinct() {
        return numDistinct;
    }

    public void setNumDistinct(String numDistinct) {
        this.numDistinct = numDistinct;
    }

    public String getLowValue() {
        return lowValue;
    }

    public void setLowValue(String lowValue) {
        this.lowValue = lowValue;
    }

    public String getHighValue() {
        return highValue;
    }

    public void setHighValue(String highValue) {
        this.highValue = highValue;
    }

    public String getNumNulls() {
        return numNulls;
    }

    public void setNumNulls(String numNulls) {
        this.numNulls = numNulls;
    }

    public String getDensity() {
        return density;
    }

    public void setDensity(String density) {
        this.density = density;
    }

    public String getNumBuckets() {
        return numBuckets;
    }

    public void setNumBuckets(String numBuckets) {
        this.numBuckets = numBuckets;
    }

    public String getSampleSize() {
        return sampleSize;
    }

    public void setSampleSize(String sampleSize) {
        this.sampleSize = sampleSize;
    }

    public String getCharacterSetName() {
        return characterSetName;
    }

    public void setCharacterSetName(String characterSetName) {
        this.characterSetName = characterSetName;
    }

    public String getCharColDeclLength() {
        return charColDeclLength;
    }

    public void setCharColDeclLength(String charColDeclLength) {
        this.charColDeclLength = charColDeclLength;
    }

    public String getGlobalStats() {
        return globalStats;
    }

    public void setGlobalStats(String globalStats) {
        this.globalStats = globalStats;
    }

    public String getUserStats() {
        return userStats;
    }

    public void setUserStats(String userStats) {
        this.userStats = userStats;
    }

    public String getAvgColLen() {
        return avgColLen;
    }

    public void setAvgColLen(String avgColLen) {
        this.avgColLen = avgColLen;
    }

    public String getCharLength() {
        return charLength;
    }

    public void setCharLength(String charLength) {
        this.charLength = charLength;
    }

    public String getCharUsed() {
        return charUsed;
    }

    public void setCharUsed(String charUsed) {
        this.charUsed = charUsed;
    }


    public static Map<String, OracleColumnProp> getFromResult(final ResultSet rs) throws SQLException {
        if (rs == null) {
            return null;
        }
        Map<String, OracleColumnProp> columnsMap = new HashMap<>();
        while (rs.next()) {
            OracleColumnProp columnProp = new OracleColumnProp() {
                {
                    //table_name
                    setTableName(rs.getString("table_name"));
                    //column_name
                    setColumnName(rs.getString("column_name"));
                    //data_type
                    setDataType(rs.getString("data_type"));
                    //data_type_mod
                    setDataTypeMod(rs.getString("data_type_mod"));
                    //data_length
                    setDataLength(rs.getString("data_length"));
                    //data_precision
                    setDataPrecision(rs.getString("data_precision"));
                    //data_scale
                    setDataScale(rs.getString("data_scale"));
                    //nullable
                    setNullable(rs.getString("nullable"));
                    //column_id
                    setColumnId(rs.getString("column_id"));
                    //default_length
                    setDefaultLength(rs.getString("default_length"));
                    //data_default
                    setDataDefault(rs.getString("data_default"));
                    //num_distinct
                    setNumDistinct(rs.getString("num_distinct"));
                    //low_value
                    setLowValue(rs.getString("low_value"));
                    //high_value
                    setHighValue(rs.getString("high_value"));
                    //density
                    setDensity(rs.getString("density"));
                    //num_nulls
                    setNumNulls(rs.getString("num_nulls"));
                    //num_buckets
                    setNumBuckets(rs.getString("num_buckets"));
                    //sample_size
                    setSampleSize(rs.getString("sample_size"));
                    //character_set_name
                    setCharacterSetName(rs.getString("character_set_name"));
                    //char_col_decl_length
                    setCharColDeclLength(rs.getString("char_col_decl_length"));
                    //global_stats
                    setGlobalStats(rs.getString("global_stats"));
                    //user_stats
                    setUserStats(rs.getString("user_stats"));
                    //global_stats
                    setGlobalStats(rs.getString("global_stats"));
                    //avg_col_len
                    setAvgColLen(rs.getString("avg_col_len"));
                    //char_length
                    setCharLength(rs.getString("char_length"));
                    //char_used
                    setCharUsed(rs.getString("char_used"));

                }
            };
            columnsMap.put(columnProp.getColumnName(), columnProp);
        }
        return columnsMap;
    }

    public OracleColumnProp() {
    }


}
